const router = require('koa-router')()
const mongoose = require('mongoose')
const China = mongoose.model('China')

router.get('/', async (ctx, next) => {
    let data
    let query = ctx.query
    
    if (query.type == "all") {
        await China.find({}, (err, docs) => {
            if (err) {
                console.log(err)
            }
            data = docs
        })
    } else {
        let c_type
        switch (query.type) {
            case "purple":
                c_type = "紫"
                break;
            case "red":
                c_type = "红"
                break;
            case "gray":
                c_type = "灰"
                break;
            case "blue":
                c_type = "蓝"
                break;
            case "green":
                c_type = "绿"
                break;
            case "yellow":
                c_type = "黄"
                break;
            case "other":
                c_type = "其他"
                break;
            default:
                break;
        }
        await China.find({ "c_type": c_type }, (err, docs) => {
            if (err) {
                console.log(err)
            }
            data = docs
        })
    }
    ctx.body = data

    await next()
})



module.exports = router